package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.result.R;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.service.LendService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-01-04
 */
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {
    @Resource
    LendService lendService;

    @ApiOperation("计算投资收益")
    @GetMapping("interestCount/{id}")
    public R getInterestCount(BigDecimal investAmount,
                              @PathVariable("id") String id){// 投资金额、年化率、期数
        BigDecimal  interestCount = lendService.getInterestCount(investAmount,id);
        return R.ok().data("interestCount",interestCount);
    }

    @ApiOperation("查询标的详情")
    @GetMapping("{id}")
    public R getById(@PathVariable("id")String id){
        Map<String, Object> map = lendService.getLendDetail(id);
        return R.ok().data("items",map);
    }
    @ApiOperation("投资列表")
    @GetMapping
    public R list(){
        List<Lend> lends = lendService.listLends();
        return R.ok().data("items",lends);
    }
}

